package com.yuanda.wordhot.web.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuanda.wordhot.entity.RoleEntity;
import com.yuanda.wordhot.service.RoleService;
import com.yuanda.wordhot.util.JsonUtils;
import com.yuanda.wordhot.web.BaseController;

/**
 * 角色管理控制器
 * @author YuBai
 * @Description
 * @Date 2013-5-2
 * @version 1.0
 * @since 1.0
 */
@Controller
@RequestMapping("/admin")
public class RoleManagerController extends BaseController{
	@Autowired
	private RoleService roleService;
	/**
	 * 增加用户
	 * @param user
	 * @return
	 */
	@RequestMapping("/saveRole")
	@ResponseBody
	public String saveRole(RoleEntity role){
		roleService.addRole(role);
		return "角色创建成功";
	}
	
	@RequestMapping("/updateRole")
	@ResponseBody
	public String updateUser(RoleEntity role){
		roleService.updateRole(role);
		return "角色更新成功！";
	}
	
	@RequestMapping("/removeRole")
	@ResponseBody
	public String removeUser(int roleId){
		roleService.deleteRole(roleId);
		return "用户删除成功！";
	}
	
	@RequestMapping("/getAllRolesWithPage")
	@ResponseBody
	public String getAllRoles(int page,int rows){
		int start = (page - 1)*rows;
		return JsonUtils.generateJsonByObject(roleService.getAllRoles(start,rows));
	}
	
	@RequestMapping("/getAllRoles")
	@ResponseBody
	public String getAllRoles(){
		return JsonUtils.generateJsonByObject(roleService.getAllRoles());
	}
}
